﻿Imports System.Windows.Data

Public Class EnumTypeCodeToBooleanConverter
    Implements IValueConverter

    'Value = La valeur de l'option dans le ViewModel
    'Parameter = Le texte du bouton
    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert

        If value Is Nothing Or parameter Is Nothing Then Return False

        'La valeur du type de code dans le VM du scénario central
        Dim CheckValue As String = value.ToString
        'Le texte du bouton
        Dim TargetValue As String = parameter.ToString

        Return CheckValue.Equals(TargetValue, StringComparison.InvariantCultureIgnoreCase)

    End Function

    'Value = Vrai ou Faux
    'Parameter = Le texte du bouton
    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack

        If value Is Nothing Or parameter Is Nothing Then Return Nothing

        Dim UseValue As Boolean = CBool(value)
        Dim targetValue As String = parameter.ToString

        If UseValue Then
            Return [Enum].Parse(targetType, targetValue)
        End If

        Return Binding.DoNothing
    End Function

End Class